package com.home.config;

import com.home.base.util.WebClientUtil;
import com.home.biz.JobLogBiz;
import com.home.biz.JobUserBiz;
import com.home.entity.JobLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author ：chenxf
 * @date ：Created in 2019/6/21 8:19
 * @description：
 * @modified By：
 * @version: $
 */
@Component
public class JobConfigTask {
    @Autowired
    private JobLogBiz jobLogBiz;
    @Autowired
    private JobUserBiz jobUserBiz;

    private WebClientUtil clientUtil;

    @Async
    public void fetchTask(){
        try {
            if(InitDataConfig.jobConfig.getDelFlg()==1){
                Thread.sleep(1000*60*InitDataConfig.jobConfig.getDura());
                fetchTask();
                return;
            }
            clientUtil=new WebClientUtil(jobLogBiz,jobUserBiz);
           boolean b= clientUtil.shopList();
            if(b){
                clientUtil.close();
                Thread.sleep(1000*10);
            }else {
                clientUtil.close();
                Thread.sleep(1000*60*InitDataConfig.jobConfig.getDura());
            }

            fetchTask();
        } catch (Exception e) {
            clientUtil.close();
            e.printStackTrace();
            jobLogBiz.insertSelective(JobLog.builder().notes("异常："+e.getMessage()).build());

            fetchTask();
        }

    }
}
